package lxbAdmin.userSystem.common;

import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

@Data
@Builder
public class ResponseData<T> implements Serializable {

    private static final long serialVersionUID = 5778573516446596671L;

    //成功或失败状态分类(success,info,warning,error)
    private String status;
    //业务状态码
    private String code;
    //业务提示信息
    private String message;
    //数据体
    private T data;

    public ResponseData() {
    }
    public ResponseData(String status, String code, String message, T data) {
        this.status = status;
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public ResponseData(String status, String code, String message) {
        this.status = status;
        this.code = code;
        this.message = message;
    }
    public ResponseData(String status, String code, T data) {
        this.status = status;
        this.code = code;
        this.data = data;
    }
    public static ResponseData success() {
        return success(null);
    }

    public static <T> ResponseData<T> success(T data) {
        return new ResponseData(ResponseType.TYPE_SUCCESS.getType(), ResponseCode.STD_SUCCESS.getCode(), ResponseCode.STD_SUCCESS.getMessage(), data);
    }

    public static <T> ResponseData<T> loginSuccess(T data) {
        return new ResponseData(ResponseType.TYPE_SUCCESS.getType(), ResponseCode.STD_LOGIN_SUCCESS.getCode(), ResponseCode.STD_LOGIN_SUCCESS.getMessage(), data);
    }

    public static <T> ResponseData<T> saveSuccess(T data) {
        return new ResponseData(ResponseType.TYPE_SUCCESS.getType(), ResponseCode.STD_SAVE_SUCCESS.getCode(), ResponseCode.STD_SAVE_SUCCESS.getMessage(), data);
    }

    public static <T> ResponseData<T> editSuccess(T data) {
        return new ResponseData(ResponseType.TYPE_SUCCESS.getType(), ResponseCode.STD_EDIT_SUCCESS.getCode(), ResponseCode.STD_EDIT_SUCCESS.getMessage(), data);
    }

    public static <T> ResponseData<T> delSuccess(T data) {
        return new ResponseData(ResponseType.TYPE_SUCCESS.getType(), ResponseCode.STD_DEL_SUCCESS.getCode(), ResponseCode.STD_DEL_SUCCESS.getMessage(), data);
    }

    public static <T> ResponseData<T> success(String code, String message, T data) {
        return new ResponseData(ResponseType.TYPE_SUCCESS.getType(), code, message, data);
    }

    /** 错误的请求， 如请求参数异常 */
    public static <T> ResponseData<T> badRequest() {
        return new ResponseData<T>(ResponseType.TYPE_ERROR.getType(),ResponseCode.STD_BAD_PARAMETERS.getCode(), ResponseCode.STD_BAD_PARAMETERS.getMessage(), null);
    }

    public static <T> ResponseData<T> badRequest(String message) {
        return new ResponseData<T>(ResponseType.TYPE_ERROR.getType(),ResponseCode.STD_BAD_PARAMETERS.getCode(), message, null);
    }

    /** 当前操作失败 */
    public static <T> ResponseData<T> fail(String message) {
        return new ResponseData<>(ResponseType.TYPE_ERROR.getType(), ErrorCode.FAIL_DEFAULT.getCode(), message, null);
    }

    public static <T> ResponseData<T> fail(String code, String message) {
        return new ResponseData<>(ResponseType.TYPE_ERROR.getType(),code, message, null);
    }

    public static <T> ResponseData<T> fail(ResponseCode responseCode) {
        return new ResponseData<T>(ResponseType.TYPE_ERROR.getType(),responseCode.getCode(), responseCode.getMessage(), null);
    }

    public static <T> ResponseData<T> fail(String code, String msg, T result) {
        return new ResponseData<T>(code, msg, result);
    }

    /** 未知异常 */
    public static <T> ResponseData<T> error() {
        return new ResponseData<>(ResponseType.TYPE_ERROR.getType(),ErrorCode.ERROR_DEFAULT.getCode(), ErrorCode.ERROR_DEFAULT.getMessage(), null);
    }
    public static <T> ResponseData<T> error( String message) {
        return new ResponseData<>(ResponseType.TYPE_ERROR.getType(),ErrorCode.ERROR_DEFAULT.getCode(), message, null);

    }
    public static <T> ResponseData<T> error(String code, String message, T data) {
        return new ResponseData(ResponseType.TYPE_ERROR.getType(), code, message, data);
    }
    public static <T> ResponseData<T> error(String code, String message) {
        return new ResponseData(ResponseType.TYPE_ERROR.getType(), code, message);
    }




    public static <T> ResponseData<T> info(String code, String message, T data) {
        return new ResponseData(ResponseType.TYPE_INFO.getType(), code, message, data);
    }

    public static <T> ResponseData<T> warning(String code, String message, T data) {
        return new ResponseData(ResponseType.TYPE_WARNING.getType(), code, message, data);
    }


}
